package com.mall.shopping.dto;

import com.mall.commons.result.AbstractRequest;
import com.mall.commons.tool.exception.ValidateException;
import com.mall.shopping.constants.ShoppingRetCode;
import lombok.Data;

/**
 *  cskaoyan
 */
@Data
public class AllProductRequest extends AbstractRequest {

    private Integer page;
    private Integer size;
    private String sort;
    private Long cid;
    private Integer priceGt;
    private Integer priceLte;

    @Override
    public void requestCheck() {
        if (page == null || size == null){
            throw new ValidateException(
                    ShoppingRetCode.REQUISITE_PARAMETER_NOT_EXIST.getCode(),
                    ShoppingRetCode.REQUISITE_PARAMETER_NOT_EXIST.getMessage());
        }
        if(page<=0){
            setPage(1);
        }
        if (size <= 0){
            setSize(10);
        }
        // 最高价和最低价，若两者都不为空，那么最高价必须比最低价高
        if (priceGt != null && priceLte != null){
            if (priceLte<priceGt){
                throw new ValidateException(
                        ShoppingRetCode.PARAMETER_VALIDATION_FAILED.getCode(),
                        "最高价不能比最低价低");
            }
        }
    }
}
